package com.hailin.lease.web.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hailin.lease.model.entity.AttrKey;
import com.hailin.lease.model.entity.AttrValue;
import com.hailin.lease.web.admin.mapper.AttrKeyMapper;
import com.hailin.lease.web.admin.service.AttrKeyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hailin.lease.web.admin.service.AttrValueService;
import com.hailin.lease.web.admin.vo.attr.AttrKeyVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author liubo
* @description 针对表【attr_key(房间基本属性表)】的数据库操作Service实现
* @createDate 2023-07-24 15:48:00
*/
@Service
@RequiredArgsConstructor
public class AttrKeyServiceImpl extends ServiceImpl<AttrKeyMapper, AttrKey>
    implements AttrKeyService{
    private final AttrValueService attrValueService;
    /**
     * 查询所有属性值与名称
     * @return
     */
    public List<AttrKeyVo> listAttrInfo() {
        List<AttrKeyVo> ans = new ArrayList<>();
        //1.先把所有的属性key查出来
        List<AttrKey> list = this.list();
        //2.根据属性值id去查对应的value
        for (AttrKey attrKey : list) {
            Long cur_Id = attrKey.getId();
            LambdaQueryWrapper<AttrValue> eq = new LambdaQueryWrapper<AttrValue>().eq(AttrValue::getAttrKeyId, cur_Id);
            List<AttrValue> list1 = attrValueService.list(eq);
            //3.查询完成后拷贝属性
            AttrKeyVo attrKeyVo = new AttrKeyVo();
            BeanUtils.copyProperties(attrKey,attrKeyVo);
            attrKeyVo.setAttrValueList(list1);
            ans.add(attrKeyVo);
        }
        return ans;
    }
}




